package kaler.radiovirsa.app.checkinternet;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.util.Log;
import static kaler.radiovirsa.app.constant.GlobalConfig.*;


public class InternetBroadcast extends BroadcastReceiver {
	String TAG = "InternetBroadcast ";

	@Override
	public void onReceive(Context context, Intent intent) {
		ConnectivityManager cm = ((ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE));
		if (cm == null)
			return;
		if (cm.getActiveNetworkInfo() != null
				&& cm.getActiveNetworkInfo().isConnected()) {
			Log.d(TAG, "INTERNET ON");
			if (isPlaying) {
				context.startService(new Intent(context,
						kaler.radiovirsa.app.service.ManageRadio.class));
			}

		} else {
			// Do nothing or notify user somehow
			Log.d(TAG, "INTERNET Off");
			context.stopService(new Intent(context,
					kaler.radiovirsa.app.service.ManageRadio.class));
		}

	}

}
